package com.jxb.three;

/**
 * 旋转图像
 * 1 2 3
 * 4 5 6
 * 7 8 9
 *
 * 右上左下对角线反转
 * 9  6  3
 * 8  5  2
 * 7  4  1
 * 三组数据
 * (0,0)->(2,2)
 * (0,1)->(1,2)
 * (0,3)->(0,3)
 *
 * (1,0)->(2,1)
 * (1,1)->(1,1)
 * (1,3)->(0,1)
 *
 *  nums[i][j] = nums[n-j][n-i]
 * 水平反转
 * 7  4  1
 * 8  5  2
 * 9  6  3
 *
 * nums[i][j] = nums[n-i,j]
 *
 * 思路：
 *  1：首先进行右上左下的对角线进行反转
 *  2：水平反转
 */
public class RotateImage_48 {

    public static void main(String[] args) {
        //[[1,2,3],[4,5,6],[7,8,9]]
        int[][] matrix = {{1,2,3},{4,5,6},{7,8,9}};
        rotate(matrix);
        System.out.println("--");
    }


    public static void rotate(int[][] matrix) {
        //组
        int n = matrix.length-1;
        for (int i = 0;i<n;i++) {
            for (int j = 0;j<n;j++) {
                int temp = matrix[i][j];
                //(0,0) = (0,2)
                matrix[i][j] = matrix[n-j][n-i];
                matrix[n-j][n-i] = temp;
            }
        }
        //中轴反转
        for (int i = 0; i <= (n >> 1); ++i){
            for (int j = 0;j<=n;++j) {
                int temp = matrix[i][j];
                matrix[i][j] = matrix[n - i][j];
                matrix[n - i][j] = temp;
            }
        }
    }


}
